if(!dojo._hasResource["opm.widgets.GenericSearchForm"]){
dojo._hasResource["opm.widgets.GenericSearchForm"] = true;
dojo.provide("opm.widgets.GenericSearchForm");
dojo.require("dijit._Widget");
dojo.require("dijit.form.Textarea");
dojo.require("dijit.form.Select");
dojo.declare("opm.widgets.GenericSearchForm",dijit._Widget,
{
   widgetId:"",
   contentId:"",
   ajaxCallUrl:"",
   ajaxCallType:"",
   data:{},
   constructor:function(args){
      this.contentId = args.contentId;
      this.widgetId = args.id;
   },
   setAtt:function(name, value){
      this[name] = value;
   },
   getAtt:function(name){
      return this[name];
   },
   setDataForm:function(data){
      this.data = data;
   },
   createForm:function(){
      var commonForm = this;
      var args = {
         ajaxUrl: this.ajaxCallUrl,
         callback: function (data){
             commonForm.setDataForm(data);
             commonForm.showForm();
      }};
      OPM.callAjaxWidget(args, this.contentId, this.ajaxCallType);
   },
   showForm:function(){
      var layout = '<div id="divSearchLayout">'; 
      layout += this.parseHeaderColumnsHtml();
      layout += this.parseCriteriaColumnsHtml();
      layout += '</div>';
      var control = dojo.byId(this.contentId);
      control.innerHTML = layout;
   },
   parseHeaderColumnsHtml:function(){
       var htmlString = '<div class="divSearchRow"><div class="infobox1"><label>'+this.data.headers[0]+'</label></div>';
       htmlString += '<div class="infobox2"><label>'+this.data.headers[1]+'</label></div>';
       htmlString += '<div class="infobox1"><label>'+this.data.headers[2]+'</label></div>';
       htmlString += '<div class="infobox2"><label>'+this.data.headers[3]+'</label></div>';
       htmlString += '</div>';
       return htmlString;
   },
   parseCriteriaColumnsHtml:function(){
       var styleDisable = "";
       var htmlString = '<div class="divSearchRow">';
       htmlString += this.parseFilterColumnsHtml('propertyCriteria','', styleDisable, this.data.criteria.properties);
       htmlString += this.parseEqualityColumnsHtml('equalityCriteria','', styleDisable, this.data.criteria.equality);
       htmlString += this.parseTextBoxHtml('valueCriteria','', styleDisable);
       htmlString += this.parseLogicColumnsHtml('logicCriteria','', styleDisable, this.data.criteria.logic);
       htmlString += '</div>';
       return htmlString;
   },
   parseFilterColumnsHtml:function(controlName, controlValue, styleDisable, dataSource){
       var htmlString = '<div class="infobox1"><select dojoType="dijit.form.Select" name="'+controlName+'" '+styleDisable+' style="width:100%">';
       for (var key in dataSource){
          var option = dataSource[key];
          var optionValue = option.value;
          htmlString += '<option value="'+optionValue+'" '+((optionValue==controlValue)?'selected':'')+'>'+option.label+'</option>';
       }
       htmlString += '</select></div>';
       return htmlString;
   },
   parseEqualityColumnsHtml:function(controlName, controlValue, styleDisable, dataSource){
       return this.parseMultiTextHtml(controlName, controlValue, styleDisable, dataSource,'infobox2');
   },
   parseTextBoxHtml:function(controlName, controlValue, styleDisable){
       var htmlString = '<div class="infobox1"><input type="text" name="'+controlName+'" value="'+controlValue+'" '+styleDisable+' dojoType="dijit.form.TextBox"></div>';
       return htmlString;
   },
   parseLogicColumnsHtml:function(controlName, controlValue, styleDisable, dataSource){
       return this.parseMultiTextHtml(controlName, controlValue, styleDisable, dataSource, 'infobox2');
   },
   parseMultiTextHtml:function(controlName, controlValue, styleDisable, dataSource, styleClass){
       var htmlString = '<div class="'+styleClass+'"><select dojoType="dijit.form.Select" name="'+controlName+'" '+styleDisable+' style="width:100%">';
       for (var indexOption=0; indexOption<dataSource.length; indexOption++){
          var option = dataSource[indexOption];
          var optionValue = option.value;
          htmlString += '<option value="'+optionValue+'" '+((optionValue==controlValue)?'selected':'')+'>'+option.label+'</option>';
       }
       htmlString += '</select></div>';
       return htmlString;
   },
});
}